<%
# Copyright (C) 2012 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<%
  content_for :page_title, "Calendar"
  js_env :CALENDAR => {
    :CONTEXTS => @contexts_json,
    :MANAGE_CONTEXTS => @manage_contexts,
    :SELECTED_CONTEXTS => @selected_contexts,
    :ACTIVE_EVENT => @active_event_id,
    :VIEW_START => @view_start,
    :CAL2_ONLY => true,
    :SHOW_SCHEDULER => @domain_root_account.show_scheduler?,
    :BETTER_SCHEDULER => @domain_root_account.feature_enabled?(:better_scheduler) && @domain_root_account.show_scheduler?,
    :MAX_GROUP_CONVERSATION_SIZE => Conversation.max_group_conversation_size,
    :VISIBLE_CONTEXTS_LIMIT => @domain_root_account.settings[:calendar_contexts_limit] || 10,
  }
  js_env :STUDENT_PLANNER_ENABLED => @domain_root_account&.feature_enabled?(:student_planner) && @current_user.has_student_enrollment?

  js_bundle :calendar2
  css_bundle :calendar2, :agenda_view
  crumbs.clear
  @body_classes << "full-width no-page-block hide-content-while-scripts-not-loaded"
%>
<h1 class="screenreader-only">{{#t}}Calendar{{/t}}</h1>

<% content_for :auto_discovery do %>
  <%= auto_discovery_link_tag(:atom, @feed_url + '.atom', {:title => t(:feed_title, "Course Calendar Atom Feed")}) %>
<% end %>

<% content_for :right_side do %>
  <a href="#" class="skip-to-calendar screenreader-only">{{#t}}Skip to calendar{{/t}}</a>

  <div class="rs-section">
    <div tabindex="0" role="note" class="screenreader-only accessibility-warning">
      <span><%= t 'Mini calendar' %></span>
      <span><%= t "Warning: For improved accessibility of calendar events, please use the agenda view." %></span>
    </div>
    <div id="minical"></div>
  </div>
  <div id="select-course-component" class="rs-section"></div>
  <div class="rs-section">
    <span role="button" id="calendar-toggle-button" class="element_toggler" aria-controls="context-list-holder" aria-expanded="true"
        aria-label="{{#t}}Calendars toggle list visibility{{/t}}" tabindex="0">
      {{> icons/mini-arrow-down}} {{#t}}Calendars{{/t}}
    </span>
    <div id="context-list-holder"></div>
  </div>
  <div class="rs-section" id="undated-events-section">
    <span href="#" role="button" id="undated-events-button" class="element_toggler" aria-controls="undated-events" aria-expanded="false"
        aria-label="{{#t}}Undated items toggle list visibility{{/t}}" tabindex="0">
      {{> icons/mini-arrow-right}} {{#t}}Undated{{/t}}
    </span>
    <div id="undated-events"></div>
  </div>
  <div class="rs-section" id="calendar-feed">
    <button class="dialog_opener Button Button--link" aria-controls="calendar_feed_box" data-dialog-opts='{"resizable":false, "width": 400}'>
      {{> icons/calendar-days}} <%= t :calendar_feed, "Calendar Feed" %>
    </button>
  </div>
<% end %>
<div style="display: none" id="calendar_feed_box" title="{{#t}}Calendar Feed{{/t}}">
  <p id="calendar-feed-message">
    <%= t "calendar_feed_instructions", "Copy the link below and paste it into any calendar app that takes iCal feeds (Google Calendar, iCal, Outlook, etc.)" %>
  </p>
  <p id="calendar-feed-box-lower">
    <input value="<%= @feed_url%>.ics"><br>
    <a href="<%= @feed_url%>.ics"><%= t "links.feed", 'click here to view the feed' %></a>
  </p>
</div>

<div id="calendar_header"></div>
<div id="calendar-app" role="tabpanel" class="<%= 'wrap-calendar-event-titles' if @wrap_titles %>"></div>
<div id="calendar-drag-and-drop-container"></div>
